package net.loyintean.pearlshell.wechat.distribute.impl;

import java.util.ArrayList;
import java.util.List;

import net.loyintean.pearlshell.wechat.distribute.IMessageDistributor;
import net.loyintean.pearlshell.wechat.model.BaseMessageModel;
import net.loyintean.pearlshell.wechat.service.DefaultMessageProcesser;
import net.loyintean.pearlshell.wechat.service.IMessageProcesser;

public class DefaultMessageDistributorImpl implements IMessageDistributor {

	private List<IMessageDistributor> distributorList;

	private IMessageProcesser defaultProcesser = new DefaultMessageProcesser();

	public DefaultMessageDistributorImpl() {
		distributorList = new ArrayList<IMessageDistributor>(0);

		distributorList.add(new SubsDistributorImpl());
		distributorList.add(new IranDistributorImpl());
		distributorList.add(new EncrMessageDistributor());
	}

	@Override
	public IMessageProcesser distribute(BaseMessageModel message) {

		IMessageProcesser processer = defaultProcesser;

		for (IMessageDistributor distributor : distributorList) {

			if (distributor.distribute(message) != null) {

				processer = distributor.distribute(message);

				break;
			}
		}

		return processer;
	}

}
